package com.example.zx.theline.lyjh.pub;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.zx.theline.R;
import com.example.zx.theline.pub.CheckInfoActivity;

import org.apache.http.Header;

import GsonBean.ShyjhxqBean;
import GsonBean.SuccessBean;
import GsonBean.post.SgbDhzPost;
import Utils.DeviceUuidFactory;
import Utils.MyToast;
import Utils.RefreshManager;
import app.MyApplication;
import base.BaseActivity;
import dialog.CenterDialog;
import network.NetWorkApi;
import network.ObjectHttpResponseHandler;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 施工办审核审批已完成已下达状态详情页
 */
@SuppressWarnings("deprecation")
public class JhshYxdActivity extends BaseActivity implements View.OnClickListener {
    public static ShyjhxqBean ZsyjhxxShBean;
    //计划内容
    private TextView lb, yf, ydbh, kssj,xm, dd, hb, lc, xmmc, sgnr, sgjx, blfh;
    // 相关单位
    private TextView sgdw, sgdwfzr, jldw, jldwfzr, jsdw, cwzd, sbgldw, qtdw, shcs, xmzgbm, currentSgqd;
    // 按钮
    private TextView tv_chakan, tv_shliucheng, tv_cancel, tv_dhz;
    private TextView rightTextView, leftTextView;

    private CenterDialog mCenterDialog; //待汇总,下达正式,下达增补
    private SgbDhzPost mSgbDhzPost;//施工办汇总Post Bean
    private LinearLayout blfh_layout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jhsh_yxdsh);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {

        TextView centerTextView = (TextView) findViewById(R.id.centerTextView);
        centerTextView.setText("月计划详情");

        lb = (TextView) findViewById(R.id.lb);
        yf = (TextView) findViewById(R.id.yf);
        ydbh = (TextView) findViewById(R.id.ydbh);
        kssj = (TextView) findViewById(R.id.kssj);
        xm = (TextView) findViewById(R.id.xm);
        dd = (TextView) findViewById(R.id.dd);
        hb = (TextView) findViewById(R.id.hb);
        lc = (TextView) findViewById(R.id.lc);
        xmmc = (TextView) findViewById(R.id.xmmc);
        sgnr = (TextView) findViewById(R.id.sgnr);
        sgjx = (TextView) findViewById(R.id.sgjx);
        blfh = (TextView) findViewById(R.id.blfh);
        blfh_layout = (LinearLayout) findViewById(R.id.blfh_layout);

        sgdw = (TextView) findViewById(R.id.sgdw);
        sgdwfzr = (TextView) findViewById(R.id.sgdwfzr);
        jldw = (TextView) findViewById(R.id.jldw);
        jldwfzr = (TextView) findViewById(R.id.jldwfzr);
        jsdw = (TextView) findViewById(R.id.jsdw);
        cwzd = (TextView) findViewById(R.id.cwzd);
        sbgldw = (TextView) findViewById(R.id.sbgldw);
        qtdw = (TextView) findViewById(R.id.qtdw);
        shcs = (TextView) findViewById(R.id.shcs);
        xmzgbm = (TextView) findViewById(R.id.xmzgbm);

        tv_cancel = (TextView) findViewById(R.id.tv_cancel);
        tv_chakan = (TextView) findViewById(R.id.tv_chakan);
        tv_shliucheng = (TextView) findViewById(R.id.tv_shliucheng);
        tv_dhz = (TextView) findViewById(R.id.tv_dhz); //待汇总
        currentSgqd = (TextView) findViewById(R.id.current_sgqd);

        leftTextView = (TextView) findViewById(R.id.leftTextView);
        rightTextView = (TextView) findViewById(R.id.rightTextView);
    }

    @Override
    protected void InitData() {
        rightTextView.setVisibility(View.GONE);

        if (ZsyjhxxShBean == null) {
            MyApplication.ShowWaitDialog(this);
            MyApplication.setWaitDialogMsg("数据错误");
        } else {
            lb.setText(ZsyjhxxShBean.getInfo().getLb());
            yf.setText(ZsyjhxxShBean.getInfo().getSgny());
            ydbh.setText(ZsyjhxxShBean.getInfo().getBh());

            //日期时间
            kssj.setText(ZsyjhxxShBean.getInfo().getExsgrq());
            xm.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getXlmc());
            dd.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getSgdd());
            hb.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getXbmc());
            lc.setText(ZsyjhxxShBean.getInfo().getXlxbList().get(0).getLic());
            xmmc.setText(ZsyjhxxShBean.getInfo().getXmmc());
            sgnr.setText(ZsyjhxxShBean.getInfo().getNrmc());
            sgjx.setText(ZsyjhxxShBean.getInfo().getJxmc());
            if (ZsyjhxxShBean.getInfo().getLb().equals("C")) {
                blfh_layout.setVisibility(View.GONE);
            } else {
                blfh_layout.setVisibility(View.VISIBLE);
                blfh.setText(ZsyjhxxShBean.getInfo().getFhcsmc());
            }

            sgdw.setText(ZsyjhxxShBean.getInfo().getSgdwmc()); //施工单位名称
            sgdwfzr.setText(ZsyjhxxShBean.getInfo().getSgdwfzr());
            jldw.setText(ZsyjhxxShBean.getInfo().getJldw());
            jldwfzr.setText(ZsyjhxxShBean.getInfo().getJldwfzr());
            jsdw.setText(ZsyjhxxShBean.getInfo().getJsdwmc()); //建设单位名称
            cwzd.setText(ZsyjhxxShBean.getInfo().getCwzd());
            sbgldw.setText(ZsyjhxxShBean.getInfo().getSbgldw());
            qtdw.setText(ZsyjhxxShBean.getInfo().getQtdw());
            shcs.setText(ZsyjhxxShBean.getInfo().getShcsmc()); //审核处室名称
            xmzgbm.setText(ZsyjhxxShBean.getInfo().getSpcsmc()); //审批处室名称
            currentSgqd.setText(ZsyjhxxShBean.getInfo().getSection()); //当前施工区段
        }
    }

    @Override
    protected void InitListen() {
        tv_cancel.setOnClickListener(this);
        leftTextView.setOnClickListener(this);
        tv_chakan.setOnClickListener(this);
        tv_shliucheng.setOnClickListener(this);
        tv_dhz.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.leftTextView:
                finish();
                break;
            case R.id.tv_cancel:
                finish();
                break;
            //查看历史
            case R.id.tv_chakan:
                JhshHistoryActivity.ZsyjhxxShBean = ZsyjhxxShBean;
                Intent intent = new Intent(this, JhshHistoryActivity.class);
                startActivity(intent);
                break;
            //审核流程
            case R.id.tv_shliucheng:
                CheckInfoActivity.ZsyjhxxShBean = ZsyjhxxShBean;
                intent = new Intent(this, CheckInfoActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_dhz:
                //待汇总
                mCenterDialog = new CenterDialog(this, new CenterDialog.CenterClick() {
                    @Override
                    public void confirmListener() {
                        mSgbDhzPost = new SgbDhzPost();
                        mSgbDhzPost.setSpWcState(ZsyjhxxShBean.getInfo().getYjhCxValue());
                        mSgbDhzPost.setJdjhbBh(ZsyjhxxShBean.getInfo().getBh());
                        mSgbDhzPost.setOpeartionType("1");
                        mSgbDhzPost.setOpeartionName("待汇总");
                        mSgbDhzPost.setOpeartionWorkername(MyApplication.getmLoginUser().getTrueName());
                        mSgbDhzPost.setOpeartionIp(DeviceUuidFactory.getDeviceId(JhshYxdActivity.this));
                        mSgbDhzPost.setDeleteFlag("N");
                        mSgbDhzPost.setCjrId(MyApplication.getmLoginUser().getUserDisplayName());
                        mSgbDhzPost.setXgrId(MyApplication.getmLoginUser().getUserDisplayName());
                        MyApplication.ShowWaitDialog(JhshYxdActivity.this);
                        NetWorkApi.sgbdhz(mSgbDhzPost, new Callback<SuccessBean>() {
                                    @Override
                                    public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                                        try {
                                            SuccessBean Bean =response.body();
                                            if (Bean.getMsg().equals("success")) {
                                                MyToast.showToast("待汇总成功");
                                                mCenterDialog.dismiss();
                                                RefreshManager.Sgyjh.RefreshSpywc(); //刷新审批已完成
                                                RefreshManager.Sgyjh.RefreshShyjh();
                                                RefreshManager.Sgyjh.RefreshYjhcx();
                                                JhshYxdActivity.this.finish();
                                            }
                                        } catch (Exception e) {
                                            MyToast.showFail();
                                        }
                                        MyApplication.HideWaitDialog();
                                    }

                                    @Override
                                    public void onFailure(Call<SuccessBean> call, Throwable t) {
                                        MyToast.showFail();
                                    }
                                }
                        );
                    }

                    @Override
                    public void cancelListener() {
                        mCenterDialog.dismiss();
                    }
                });
                mCenterDialog.setMessage("该月计划已下达其相应的周和日会被作废，您确定要切换为待汇总吗？");
                mCenterDialog.show();
                break;
            default:
                break;
        }
    }

}
